#include<iostream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
using namespace std;
void test1(int argc,char* a[])
{
    for(int i=0;i<argc;i++)
    {
        printf("./cmd->a[%d]:%s",i,a[i]);
        cout<<endl;
    }
    return;
}

//各选项功能的选择
void test2(int argc,char*a[])
{
    if(argc!=2)
    {
        printf("./cmd->a[a|b|c|d]\n");
        return;
    }
    
    if(strcmp(a[1],"-a")==0)
    {
        cout<<"功能1"<<endl;
    }
    else  if(strcmp(a[1],"-b")==0)
    {
        cout<<"功能2"<<endl;
    }

   else  if(strcmp(a[1],"-c")==0)
    {
        cout<<"功能3"<<endl;
    }

   else  if(strcmp(a[1],"-d")==0)
    {
        cout<<"功能4"<<endl;
    }
    else 
    {
        cout<<"没有此功能"<<endl;
    }
    return;
}

//环境变量的打印
void test3(char*env[])
{
    for(int i=0;env[i];i++)
    {
        printf("env[%d]->:%s\n",i,env[i]);
    }
}

//内建命令
void test4(int argc,char*argv[])
{
    if(strcmp(argv[1],"cd")==0)
    {
        
       cout<<"开始改变路径"<<endl;
       sleep(50);
        chdir(argv[2]);
        cout<<"改变路径完成"<<endl;
        sleep(30);
    }
    else{
        cout<<"不是cd命令"<<endl;
    }
}

int main(int argc,char* argv[],char*env[])
{
   // test1(argc,argv);
   // test2(argc,argv);
   //   test3(env);
      test4(argc,argv);
    return 0;
}
    
